package com.study8.demo8.controller;

import com.study8.demo8.service.MyService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName MyController2
 * @Description: TODO
 * @Author: Peak Croft
 * @Date: 2022/3/30 13:30
 * @Version 1.0
 */
@RestController
public class MyController2 {

  @Resource
  MyService myService;

  // 获得全局数据
  @GetMapping("/globalData")
  public String global(Model model){
    Map<String,Object> map = model.asMap();
    Set<String> keySet = map.keySet();
    String resultString = "";
    for (String s : keySet) {
      resultString += s+":"+map.get(s);
    }
    return resultString;
  }

  // 拦截器
  @GetMapping("/interceptor")
  public String interceptor(){

    return "拦截失败";
  }

  // AOP拦截Service
  @GetMapping("/service")
  public String toService(){

    return myService.aopInterceptor();
  }

}
